//******************************************************************************
//* Party Singleton Object for Character
//******************************************************************************
unit SUParty;

interface
  uses
    Generics.Collections;

  type
    PParty = class
      private
        m_AllowLooting : Boolean;
        class var _Instance : PParty;
        constructor Create;overload;
        function Sin_GetAllowLooting: Boolean;
        procedure Sin_SetAllowLooting(const Value: Boolean);
        function Sin_GetMembers: TList<Cardinal>;
        function Sin_GetPartyState: Boolean;
      public
        class function GetInstance():PParty;

        function Invite(ObjectID:Cardinal):Boolean;
        //function Invite(ObjectID:Mobile):Boolean;
        function Remove(ObjectID:Cardinal):Boolean;
        //function Remove(ObjectID:Mobile):Boolean;
        function Whisper(ObjectID:Cardinal;Msg:String):Boolean; overload;
        //function Whisper(ObjectID:Mobile;Msg:String):Boolean;
        function Whisper(Msg:String):Boolean; overload;

        function Accept():Boolean;
        function Decline():Boolean;
        function Leave():Boolean;

        property AllowLooting : Boolean         read Sin_GetAllowLooting write Sin_SetAllowLooting;
        property InParty      : Boolean         read Sin_GetPartyState;
        property Members      : TList<Cardinal> read Sin_GetMembers;
      end;
implementation
  uses
    SuStealth;

{ UParty }

function PParty.Accept: Boolean;
begin
  Result := False;
  if(InParty)then exit;
  Script.Party.PartyAcceptInvite;
  Result := True;
end;

constructor PParty.Create;
begin
  // not used....
end;

function PParty.Decline: Boolean;
begin
  Result := False;
  if(InParty)then exit;
  Script.Party.PartyDeclineInvite;
  Result := True;
end;

class function PParty.GetInstance: PParty;
begin
  if not Assigned(_Instance) then _Instance := PParty.Create;
  Result := _Instance;
end;

function PParty.Invite(ObjectID: Cardinal): Boolean;
begin
  Result := False;
  if(not TUOObject.IsObjectExists(ObjectID)) then exit;
  if(not Script.Connection.Connected) then exit;
  if(TUOObject.GetDistance(ObjectID)>10)then exit;
  Script.Party.InviteToParty(ObjectID);
  Result := True;
end;

function PParty.Leave: Boolean;
begin
  Result := False;
  if(not InParty)then exit;
  Script.Party.PartyLeave;
  Result := True;
end;

function PParty.Remove(ObjectID: Cardinal): Boolean;
begin
  Result := False;
  if(not Script.Connection.Connected) then exit;
  Script.Party.RemoveFromParty(ObjectID);
  Result := True;
end;

function PParty.Sin_GetAllowLooting: Boolean;
begin
  Result := m_AllowLooting;
end;

function PParty.Sin_GetMembers: TList<Cardinal>;
var
  arr : TArray<Cardinal>;
begin
  arr := Script.Party.PartyMembersList;
  Result := TList<Cardinal>.Create;
  Result.AddRange(arr);
end;

function PParty.Sin_GetPartyState: Boolean;
begin
  Result := Script.Party.InParty;
end;

procedure PParty.Sin_SetAllowLooting(const Value: Boolean);
begin
  m_AllowLooting := Value;
  Script.Party.PartyCanLootMe(Value);
end;

function PParty.Whisper(ObjectID: Cardinal; Msg: String): Boolean;
begin
  Result := False;
  if(not Script.Connection.Connected) then exit;
  Script.Party.PartyMessageTo(ObjectID,Msg);
  Result := True;
end;

function PParty.Whisper(Msg: String): Boolean;
begin
  Result := False;
  if(not Script.Connection.Connected) then exit;
  Script.Party.PartySay(Msg);
  Result := True;
end;

end.